﻿using UnityEngine;
using System.Collections;
using Spine.Unity;
using System;
using static Spine.AnimationState;

public class SpineCtrl : MonoBehaviour {
    [SerializeField]
    private SkeletonAnimation spineAnim;
    // Use this for initialization

    TrackEntryDelegate _endCall;
    public void DoAni(string aniName, bool loop, bool needClear,Action endCall=null)
    {
        if(needClear)
        {
             spineAnim.state.ClearTracks();
        }
        _endCall = delegate
        {
            spineAnim.AnimationState.Complete -= _endCall;
            if (endCall!=null)
            {
                endCall();
            }
        };
 
        spineAnim.state.SetAnimation(0, aniName, loop);
        spineAnim.AnimationState.Complete += _endCall;

        
    }
}
